// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sysin

import (
	"context"
	"hotgo/internal/consts"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"
	"hotgo/utility/validate"

	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

// MemberCardUpdateFields 修改会员中心字段过滤
type MemberCardUpdateFields struct {
	ImgUrl        string  `json:"imgUrl"        dc:"图片"`
	Name          string  `json:"name"          dc:"名称"`
	Price         float64 `json:"price"         dc:"价格(元)"`
	ExchangeCount int     `json:"exchangeCount" dc:"可兑换次数"`
	MemberDays    int     `json:"memberDays"    dc:"会员天数"`
	ExtraDays     int     `json:"extraDays"     dc:"额外赠送天数"`
	MemberProfit  float64 `json:"memberProfit"  dc:"会员分润"`
	SaleProfit    float64 `json:"saleProfit"    dc:"销氪分润"`
	ServiceProfit float64 `json:"serviceProfit" dc:"服务商分润"`
}

// MemberCardInsertFields 新增会员中心字段过滤
type MemberCardInsertFields struct {
	ImgUrl        string  `json:"imgUrl"        dc:"图片"`
	Name          string  `json:"name"          dc:"名称"`
	Price         float64 `json:"price"         dc:"价格(元)"`
	ExchangeCount int     `json:"exchangeCount" dc:"可兑换次数"`
	MemberDays    int     `json:"memberDays"    dc:"会员天数"`
	ExtraDays     int     `json:"extraDays"     dc:"额外赠送天数"`
	MemberProfit  float64 `json:"memberProfit"  dc:"会员分润"`
	SaleProfit    float64 `json:"saleProfit"    dc:"销氪分润"`
	ServiceProfit float64 `json:"serviceProfit" dc:"服务商分润"`
}

// MemberCardEditInp 修改/新增会员中心
type MemberCardEditInp struct {
	entity.MemberCard
}

func (in *MemberCardEditInp) Filter(ctx context.Context) (err error) {
	// 验证图片
	//if err := g.Validator().Rules("required").Data(in.ImgUrl).Messages("图片不能为空").Run(ctx); err != nil {
	//	return err.Current()
	//}

	// 验证名称
	if err := g.Validator().Rules("required").Data(in.Name).Messages("名称不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证价格(元)
	if err := g.Validator().Rules("regex:(^[0-9]{1,10}$)|(^[0-9]{1,10}[\\.]{1}[0-9]{1,2}$)").Data(in.Price).Messages("价格(元)最多允许输入10位整数及2位小数").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证可兑换次数
	if err := g.Validator().Rules("required").Data(in.ExchangeCount).Messages("可兑换次数不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证会员天数
	if err := g.Validator().Rules("required").Data(in.MemberDays).Messages("会员天数不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	// 验证额外赠送天数
	if err := g.Validator().Rules("required").Data(in.ExtraDays).Messages("额外赠送天数不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type MemberCardEditModel struct{}

// MemberCardViewInp 获取指定会员中心信息
type MemberCardViewInp struct {
	Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
}

func (in *MemberCardViewInp) Filter(ctx context.Context) (err error) {
	return
}

type MemberCardViewModel struct {
	entity.MemberCard
}

// MemberCardListInp 获取会员中心列表
type MemberCardListInp struct {
	form.PageReq
}

func (in *MemberCardListInp) Filter(ctx context.Context) (err error) {
	return
}

type MemberCardListModel struct {
	entity.MemberCard
}

// MemberCardStatusInp 更新会员中心状态
type MemberCardStatusInp struct {
	Id     int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
	Status int   `json:"status" dc:"状态"`
}

func (in *MemberCardStatusInp) Filter(ctx context.Context) (err error) {
	if in.Id <= 0 {
		err = gerror.New("ID不能为空")
		return
	}

	if in.Status <= 0 {
		err = gerror.New("状态不能为空")
		return
	}

	if !validate.InSlice(consts.StatusSlice, in.Status) {
		err = gerror.New("状态不正确")
		return
	}
	return
}

type MemberCardStatusModel struct{}
